package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysPsyKnowledge;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.service.SysPsyKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SysPsyKnowledgeController {
    @Autowired
    private SysPsyKnowledgeService sysPsyKnowledgeService;

    /*
     * 新增
     * */
    @PostMapping("/sysPsyKnowledge")
    public Result add(@RequestBody SysPsyKnowledge sysPsyKnowledge){
        int num =sysPsyKnowledgeService.add(sysPsyKnowledge);
        return num > 0 ? Result.success() : Result.error();
    }

    /*
     * 删除
     * */
    @DeleteMapping("/sysPsyKnowledge/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = sysPsyKnowledgeService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/sysPsyKnowledge")
    public Result removeBatch(Integer[] ids){
        int num = sysPsyKnowledgeService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();

    }

    @PutMapping("/sysPsyKnowledge")
    public Result edit(@RequestBody SysPsyKnowledge sysPsyKnowledge){
        int num = sysPsyKnowledgeService.edit(sysPsyKnowledge);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/sysPsyKnowledge/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysPsyKnowledge sysPsyKnowledge= sysPsyKnowledgeService.findById(id);
        return Result.success(sysPsyKnowledge);
    }

    @GetMapping("/sysPsyKnowledge")
    public Result findAll(SysPsyKnowledge sysPsyKnowledge){
        List<SysPsyKnowledge> list = sysPsyKnowledgeService.find(sysPsyKnowledge);
        return Result.success(list);
    }

    @GetMapping("/sysPsyKnowledge/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysPsyKnowledge sysPsyKnowledge) {

        Map<String, Object> map = sysPsyKnowledgeService.findPage(pageNum, pageSize, sysPsyKnowledge);
        return Result.success(map);
    }

}
